import { Module } from 'vuex';
import {getStorage} from '/@/request/file.js';
import { ElMessage } from 'element-plus';

const wangpanSideMenuModule: Module<WangpanSideMenuState, RootStateTypes> ={
	namespaced: true,
    state: {
        isFold: window.sessionStorage.getItem("isWangpanFold"),
        storageUsedValue: 0, //  已使用存储容量
        storageMaxValue: 0 //  最大存储容量
    },
    mutations: {
        switchFold(state) {
            state.isFold =  !state.isFold
            window.sessionStorage.setItem("isWangpanFold", state.isFold);
        },
        setStorageInfo(state, storageInfo) {
            state.storageUsedValue = Number(storageInfo.usedStorage)
            state.storageMaxValue = Number(storageInfo.maxStorage)
        }
    },
    actions: {
        async showStorage({ commit }) {			
			return getStorage().then(res => {
                commit('setStorageInfo', res);
            }).catch(err => {
				ElMessage.error('err.msg');
			});			
        }
    }
};


export default wangpanSideMenuModule;